export default {
    showErrLog:true,
    remoteImgLoader(url,targetSprite){
        if(targetSprite instanceof cc.Sprite){
            cc.loader.load({url: url, type: 'png'}, (err,texture2D) => this.loadimg(err,texture2D,targetSprite));
        }else{
            if(this.showErrLog){
                console.log(targetSprite , 'is not Sprite')
            }
        }
    },
    localImgLoader(resUrl,targetSprite){
        if(targetSprite instanceof cc.Sprite){
            cc.loader.loadRes(resUrl, (err,texture2D) => {this.loadimg(err,texture2D,targetSprite)});
        }else{
            if(this.showErrLog){
                console.log(targetSprite , 'is not Sprite')
            }
        }
    },
    plistLoader(resUrl,name,targetSprite){
        try{
            if(targetSprite instanceof cc.Sprite){
                cc.loader.loadRes(resUrl,cc.SpriteAtlas, (err,atlas) => {
                    targetSprite.spriteFrame = atlas.getSpriteFrame(name)
                });
            }else{
                if(this.showErrLog){
                    console.log(targetSprite , 'is not Sprite')
                }
            }
        }catch(err){
            if(this.showErrLog){
                console.log(err)
            }
        }
        
    },
    loadimg(err,texture2D,targetSprite) {
        if(!err){
            targetSprite.spriteFrame = new cc.SpriteFrame(texture2D,cc.Rect(texture2D.width,texture2D.height))
        }else{
            if(this.showErrLog){
                //console.log(err)
            }
        }
    },
}